home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
prog
/
m2menu.zip
/
MENUIO.MOD
< prev
next >
Wrap
Text File
|
1990-03-22
|
3KB
|
107 lines
IMPLEMENTATION MODULE MenuIO; (* JPI TopSpeed Modula-2 V1.16 *)
IMPORT AsmLib, Lib, Storage, Str, SYSTEM;
PROCEDURE Delay(n:CARDINAL);
CONST Delay = AsmLib.Delay;
BEGIN
Delay(n)
END Delay;
(* Delay pauses program a CARDINAL value of milliseconds. 1000 = 1 sec. *)
PROCEDURE EnvFind(name:ARRAY OF CHAR; VAR result:ARRAY OF CHAR);
VAR n : CARDINAL;
pi : ARRAY[0..14] OF CHAR;
es : ARRAY[0..80] OF CHAR;
pp : Lib.CommandType;
BEGIN
n := 0;
LOOP
pp := Lib.Environment(n);
Str.Copy(es,pp^);
IF es[0] = CHR(0) THEN
result[0] := CHR(0);
RETURN
END;(*IF*)
Str.ItemS(pi,es,' =',0);
IF Str.Match(pi,name) THEN
Str.ItemS(result,es,' =',1);
RETURN
END;(*IF*)
INC(n)
END;(*LOOP*)
END EnvFind;
(* EnvFind finds a string in the DOS environment *)
PROCEDURE Exec (command:ARRAY OF CHAR; params:ARRAY OF CHAR);
VAR memptr : ADDRESS;
memsize : CARDINAL;
reply : CARDINAL;
BEGIN
memsize := Storage.HeapAvail ( Storage.MainHeap )-8;
(* 8 for MSDOS relocation *)
Storage.HeapAllocate(Storage.MainHeap,memptr,memsize);
reply := Lib.Execute(command,params,memptr,memsize);
Storage.HeapDeallocate(Storage.MainHeap,memptr,memsize);
IF reply <> 0 THEN
Lib.FatalError('Failed to execute program ')
END;(*IF*)
END Exec;
(* Exec executes a named program, using all free heap memory to do so. *)
(* All memory allocation/deallocation is automatic. Include ext & Path *)
(* eg Exec('\COM\ED.EXE','AFILE'); will be passed as the 'command line'*)
PROCEDURE ExecCmd(command:ARRAY OF CHAR);
VAR
path : ARRAY[0..63 ] OF CHAR;
cline : ARRAY[0..128] OF CHAR;
BEGIN
EnvFind('COMSPEC',path);
Str.Concat(cline,'/C ',command);
Exec(path,cline)
END ExecCmd;
(* ExecCmd is similar to Exec except the command is executed under *)
(* COMMAND.COM, the DOS command interpreter. This means that the *)
(* command can be exactly as typed from the normal DOS prompt, and *)
(* may include 'built in' commands such as DIR, COPY etc. *)
(* Examples: ExecCmd('dir /w'); (* do a 'wide' DOS directory *) *)
(* ExecCmd('ed afile'); (* same as Exec example above *) *)
(* ExecCmd is generally preferred over Exec for general use *)
(* although it has two disadvantages: *)
(* 1) There is slightly less memory available to run the command, *)
(* 2) COMMAND.COM must be re-loaded which is slightly slower. *)
PROCEDURE GetKey(VAR sc:CHAR): CHAR;
VAR r:SYSTEM.Registers;
BEGIN
WITH r DO
AH := 0;
Lib.Intr(r,16H);
IF AH # 0 THEN
sc := CHR(AH)
ELSE
sc := CHR(AH-128)
END(*IF*);
IF sc > CHR(127) THEN
AL := AH
END(*IF*);
IF AL # 0 THEN
RETURN CHR(AL)
ELSE
RETURN CHR(AH+128)
END(*IF*);
END(*WITH*)
END GetKey;
(* GetKey returns Char and scan code *)
END MenuIO.